<?php
require_once('../model/class.cms.php');
require_once('../model/class.cms_cates.php');
$qiCms = new qiCms($DB);
$qicmsCate = new qicmsCate($DB);

$cmsCates = $qicmsCate->getcmsCate();

if($ts == 'list')
{
$cmss = $qiCms->getCms();
}

if($ts == 'add')
{
$cateid = isset($_POST['cid']) ? $_POST['cid'] : '';
$cmstitle = isset($_POST['title']) ? $_POST['title'] : '';
$cmscontent = isset($_POST['content']) ? $_POST['content'] : '';
if(!empty($cmstitle)){
$qiCms->addCms($cateid,$cmstitle,$cmscontent);
header("Location: index.php?action=cms&ts=list");
}
}

if($ts == 'edit')
{
$cmsid = isset($_GET['id']) ? $_GET['id'] : '';
$cmsData = $qiCms->getOneCms($cmsid);
}

if($ts=='update')
{
$cateid = isset($_POST['cid']) ? $_POST['cid'] : '';
$cmstitle = isset($_POST['title']) ? $_POST['title'] : '';
$cmscontent = isset($_POST['content']) ? $_POST['content'] : '';
$cmsid = isset($_GET['id']) ? intval($_GET['id']) : '';

$cmsData = array(
'cid' => $cateid,
'title' => $cmstitle,
'content' => $cmscontent
);

$qiCms->updateCms($cmsData,$cmsid);

header("Location: index.php?action=cms&ts=list");
}

if($ts == 'del')
{
$cmsid = isset($_GET['id']) ? $_GET['id'] : '';
$qiCms->deleteCms($cmsid);
header("Location: index.php?action=cms&ts=list");
}

?>